package org.example.neusoft.view;

import org.example.neusoft.dao.UserDao;
import org.example.neusoft.model.User;
import org.example.neusoft.util.GlobalInput;

import java.util.Scanner;
import java.util.UUID;

public class UserView {
    public User regUser(){
        User user = new User();
        Scanner scanner = GlobalInput.getScanner();
        System.out.println("请输入email：");
        String email = scanner.nextLine();
        user.setEmail(email);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        user.setUsername(username);
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        user.setPassword(password);
        UUID uuid = UUID.randomUUID();
        user.setId(uuid.toString());
        UserDao userDao = new UserDao();
        if(userDao.regUser(user)){
            return user;
        }
        else{
            return null;
        }
    }
    public User loginUser(){
        User user = new User();
        Scanner scanner = GlobalInput.getScanner();
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        user.setUsername(username);
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        user.setPassword(password);

        UserDao userDao = new UserDao();
        return userDao.loginUser(user);
    }
}
